package com.draem0507.refactor;

import java.util.List;

/**
 * @title 提取方法对象
 * @desc
 * @atuh lwx
 * @createtime on 2015/11/14 12:24
 */
public class Day_13 {




    public class Order1
    {
        private List<OrderLineItem> OrderLineItems ;
        private List<Integer> Discounts;
        private int Tax ;

        public int Calculate(){

            return new OrderCalculator(this).Calculate();
        }


    }



    public  class OrderCalculator{
        private Order1 order;
        private List<OrderLineItem> OrderLineItems ;
            private List<Integer> Discounts;
            private int Tax ;

        public OrderCalculator(Order1 order){

            this.order=order;
        }

        public int Calculate()
        {
            int subTotal = 0;

            // Total up line items
            for (OrderLineItem lineItem : OrderLineItems)
            {
                subTotal += lineItem.Price;
            }

            // Subtract Discounts
            for (int discount : Discounts)
                subTotal -= discount;

            // Calculate Tax
            int tax = subTotal * Tax;

            // Calculate GrandTotal
            int grandTotal = subTotal + tax;

            return grandTotal;
        }



    }




    public class OrderLineItem
    {
        public int Price ;
    }

    public class Order
    {
        private List<OrderLineItem> OrderLineItems ;
        private List<Integer> Discounts;
        private int Tax ;

        public int Calculate()
        {
            int subTotal = 0;

            // Total up line items
            for (OrderLineItem lineItem : OrderLineItems)
            {
                subTotal += lineItem.Price;
            }

            // Subtract Discounts
            for (int discount : Discounts)
            subTotal -= discount;

            // Calculate Tax
            int tax = subTotal * Tax;

            // Calculate GrandTotal
            int grandTotal = subTotal + tax;

            return grandTotal;
        }
    }



}
